package controll

import (
	"SalesMangent/function"
	"SalesMangent/models"
	"fmt"

	"github.com/gin-gonic/gin"
)

func GetIventory(c *gin.Context) {
	db := function.GetDB()
	var iventorydata []models.Iventory
	db.Table("inventory").Select("i_code, f_code, i_explain, i_price, i_amount, i_weight").Order("i_code ASC").Find(&iventorydata)
	c.JSON(200, iventorydata)
}

func UpdateIventory(c *gin.Context) {
	db := function.GetDB()
	requestiventory := make(map[string]interface{})
	c.ShouldBind(&requestiventory)
	var iventorydata models.Iventory
	fmt.Println(requestiventory)
	iventorydata.Icode = requestiventory["Ucode"].(string)
	iventorydata.Fcode = requestiventory["Ufcode"].(string)
	iventorydata.Iexplain = requestiventory["Uiexplain"].(string)
	iventorydata.Iprice = requestiventory["Uiprice"].(string)
	iventorydata.Iamount = requestiventory["Uiamount"].(string)
	iventorydata.Iweight = requestiventory["Uiweight"].(string)
	db.Table("inventory").Where("i_code = ?", iventorydata.Icode).Updates(&iventorydata)
	c.JSON(200, gin.H{
		"code": 200,
	})
}
